<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Card Reader WebSocket</title>
    <script>
      const socket = new WebSocket("ws://localhost:8080/ws/card")

      socket.onopen = () => {
        // console.log("WebSocket连接成功")
      }

      socket.onmessage = (event) => {
        console.log("收到消息: ", event.data)
        // 处理返回的卡号
        alert("卡号: " + event.data)
      }

      socket.onerror = (error) => {
        console.log("WebSocket错误: ", error)
      }

      socket.onclose = () => {
        console.log("WebSocket连接关闭")
      }

      function requestCardId() {
        socket.send("getCardId")
      }
    </script>
  </head>
  <body>
    <h1>读取IC卡号</h1>
    <button onclick="requestCardId()">获取卡号</button>
  </body>
</html>
